<?php
$text = strtolower(htmlspecialchars($_GET['text'])); 
$make_blue = strtolower(htmlspecialchars($_GET['blue']));

// Write the text
if ($text != '') {
    $dyn_width = (strlen($text) * 24);    
    
    //generate image
    $image = imagecreatetruecolor($dyn_width, 35);
    
    imagealphablending($image, false);
    imagesavealpha($image, true);
    
    if ($make_blue !== '1') {
        $foreground = imagecolorallocate($image, 255, 255, 255);
        $shadow = imagecolorallocate($image, 0, 0, 0);
    }
    
    else {
        $foreground = imagecolorallocate($image, 56, 101, 157);        
        $shadow = imagecolorallocate($image, 255, 255, 255);
    }

    $background = imagecolorallocatealpha($image, 255, 255, 255, 127);
    
    imagefilledrectangle($image, 0, 0, $dyn_width, $dyn_width, $background);
    
    // use your own font if you want!
    $font = '../fonts/28DaysLater.ttf';
    
    //draw text:
    imagettftext($image, 38, 0, 15, 43, $shadow, $font, $text);
    imagettftext($image, 38, 0, 14, 40, $shadow, $font, $text);
    imagettftext($image, 38, 0, 12, 42, $foreground, $font, $text);     
}

// Create a 1x1 blank image to avoid errors
else {
    $image = imagecreatetruecolor(1, 1);
    $background = imagecolorallocatealpha($image, 255, 255, 255, 127);
    imagefilledrectangle($image, 0, 0, 1, 1, $background);
}    

//send image to browser
header ("Content-type: image/png");
imagepng($image);
imagedestroy($image);

?>